#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void url_encode_char(char *vj, int va)
{
	//1: /x $rsp = 0x7fffffffe168
	//2: /x $rbp = 0x7fffffffe180
    /*1169:	f3 0f 1e fa          	endbr64 
    116d:	55                   	push   %rbp		// rsp = 0x7fffffffe160
    116e:	48 89 e5             	mov    %rsp,%rbp	// rsp=rbp=0x7fffffffe160
    1171:	48 83 ec 30          	sub    $0x30,%rsp	// rsp = 0x7fffffffe130
    1175:	48 89 7d d8          	mov    %rdi,-0x28(%rbp) */	// 0x7fffffffe138: 0x00007fffffffe173
		char *j = vj;
		char var = va;
		
    /*1179:	89 f0                	mov    %esi,%eax		// eax = parameter 2 = 'a' = 0x61
    117b:	88 45 d4             	mov    %al,-0x2c(%rbp)	// (rbp-0x2c) = 0x7fffffffe134: 0xffffe17300000061
    117e:	64 48 8b 04 25 28 00 	mov    %fs:0x28,%rax
    1185:	00 00 
    1187:	48 89 45 f8          	mov    %rax,-0x8(%rbp)
    118b:	31 c0                	xor    %eax,%eax*/

    /*118d:	48 b8 30 31 32 33 34 	movabs $0x3736353433323130,%rax	// rax = "01234567"
    1194:	35 36 37 
    1197:	48 ba 38 39 41 42 43 	movabs $0x46444342413938,%rdx	// rdx = "89ABCDEF"
    119e:	44 46 00 */
		char s[] = {'0', '1','2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; 

    /*11a1:	48 89 45 e0          	mov    %rax,-0x20(%rbp)		// (rbp-0x20) = "01234567"
    11a5:	48 89 55 e8          	mov    %rdx,-0x18(%rbp)		// (rbp-0x18) = "89ABCDEF"
    11a9:	48 8b 45 d8          	mov    -0x28(%rbp),%rax		// rax = parameter1
    11ad:	c6 00 25             	movb   $0x25,(%rax)			// parameter1 = '%'*/
		vj[0] = '%';

    /*11b0:	0f b6 45 d4          	movzbl -0x2c(%rbp),%eax		// eax = 0x61
    11b4:	c0 f8 04             	sar    $0x4,%al				// al <<= 4 = 0x61>>4 = 0x6
    11b7:	0f be c0             	movsbl %al,%eax				// eax = 0x6
    11ba:	83 e0 0f             	and    $0xf,%eax			// eax = 0x6
    11bd:	89 c1                	mov    %eax,%ecx			// ecx = 0x6
    11bf:	48 8b 45 d8          	mov    -0x28(%rbp),%rax		// rax = parameter1
    11c3:	48 8d 50 01          	lea    0x1(%rax),%rdx		// rdx = praramter1 + 1
    11c7:	48 63 c1             	movslq %ecx,%rax			// rax = 0x6
    11ca:	0f b6 44 05 e0       	movzbl -0x20(%rbp,%rax,1),%eax	// eax = s[6] = '6'
    11cf:	88 02                	mov    %al,(%rdx)				// (praramter1 + 1) = '6' */
		vj[1] = s[va>>4];

    /*11d1:	48 8b 45 d8          	mov    -0x28(%rbp),%rax		// rax = parameter1
    11d5:	48 83 c0 01          	add    $0x1,%rax			// rax = parameter1 + 1
    11d9:	0f b6 00             	movzbl (%rax),%eax			// eax = 0x36 = '6'
    11dc:	0f be c0             	movsbl %al,%eax				// eax = 0x36
    11df:	89 c6                	mov    %eax,%esi			// esi = 0x36
    11e1:	48 8d 3d 1c 0e 00 00 	lea    0xe1c(%rip),%rdi        # 2004 <_IO_stdin_used+0x4>
    11e8:	b8 00 00 00 00       	mov    $0x0,%eax
    11ed:	e8 7e fe ff ff       	callq  1070 <printf@plt>*/
		printf("%c\n", j[1]);

    /*11f2:	0f be 45 d4          	movsbl -0x2c(%rbp),%eax		// eax = 0x61
    11f6:	83 e0 0f             	and    $0xf,%eax			// eax = 0x1
    11f9:	89 c1                	mov    %eax,%ecx			// ecx = 1
    11fb:	48 8b 45 d8          	mov    -0x28(%rbp),%rax		// rax = parameter1
    11ff:	48 8d 50 02          	lea    0x2(%rax),%rdx		// rdx = parameter1 + 2
    1203:	48 63 c1             	movslq %ecx,%rax			// rax = 1
    1206:	0f b6 44 05 e0       	movzbl -0x20(%rbp,%rax,1),%eax	// eax = s[1] = 0x31 = '1'
    120b:	88 02                	mov    %al,(%rdx)*/			// parameter1 + 2 = '1'
		vj[2] = s[va&0xf];

    /*120d:	90                   	nop
    120e:	48 8b 45 f8          	mov    -0x8(%rbp),%rax
    1212:	64 48 33 04 25 28 00 	xor    %fs:0x28,%rax
    1219:	00 00 
    121b:	74 05                	je     1222 <url_encode_char+0xb9>
    121d:	e8 3e fe ff ff       	callq  1060 <__stack_chk_fail@plt>
    1222:	c9                   	leaveq 
    1223:	c3                   	retq   */
}

int main()
{
	//1: $rsp = (void *) 0x7fffffffe188
	//2: $rbp = (void *) 0x0
    /*1224:	f3 0f 1e fa          	endbr64			// $rsp = (void *) 0x7fffffffe188
    1228:	55                   	push   %rbp		// $rsp = (void *) 0x7fffffffe180	$rbp = (void *) 0x0
    1229:	48 89 e5             	mov    %rsp,%rbp	// rsp=rbp=0x7fffffffe180
    122c:	48 83 ec 10          	sub    $0x10,%rsp	// $rsp = (void *) 0x7fffffffe170
    1230:	64 48 8b 04 25 28 00 	mov    %fs:0x28,%rax	// rax=0xf1579181adc48600	eax=0xadc48600
    1237:	00 00 
    1239:	48 89 45 f8          	mov    %rax,-0x8(%rbp)	// 0x7fffffffe178: 0xf1579181adc48600		

    123d:	31 c0                	xor    %eax,%eax*/		// eax=0	rax=0

	/*(gdb) x/16b $rbp-0xd
		0x7fffffffe173: 0xff    0xff    0x7f    0x00    0x00    0x00    0x86    0xc4
		0x7fffffffe17b: 0xad    0x81    0x91    0x57    0xf1    0x00    0x00    0x00
	(gdb) x/16b $rbp-0x10
		0x7fffffffe170: 0x70    0xe2    0xff    0xff    0xff    0x7f    0x00    0x00
		0x7fffffffe178: 0x00    0x86    0xc4    0xad    0x81    0x91    0x57    0xf1*/

    //123f:	c7 45 f3 00 00 00 00 	movl   $0x0,-0xd(%rbp)	// 0x7fffffffe173: 0xc486000000000000

	/*(gdb) x/16b $rbp-0xd 
		0x7fffffffe173: [0x00    0x00    0x00    0x00]    0x00    0x00    0x86    0xc4
		0x7fffffffe17b: 0xad    0x81    0x91    0x57    0xf1    0x00    0x00    0x00
	(gdb) x/24b $rbp-0x10  
		0x7fffffffe170: 0x70    0xe2    0xff    [0x00    0x00    0x00    0x00]    0x00
		0x7fffffffe178: 0x00    0x86    0xc4    0xad    0x81    0x91    0x57    0xf1
		0x7fffffffe180: 0x00    0x00    0x00    0x00    0x00    0x00    0x00    0x00*/

	char j[5] = {0}; 
    
	//1246:	c6 45 f7 00          	movb   $0x0,-0x9(%rbp)	// 0x7fffffffe177: 0x00

	/*(gdb) x/24b $rbp-0x10 
		0x7fffffffe170: 0x70    0xe2    0xff    0x00    0x00    0x00    0x00    [0x00]
		0x7fffffffe178: 0x00    0x86    0xc4    0xad    0x81    0x91    0x57    0xf1
		0x7fffffffe180: 0x00    0x00    0x00    0x00    0x00    0x00    0x00    0x00*/

	//char i = 0;
    
	/*124a:	48 8d 45 f3          	lea    -0xd(%rbp),%rax
    124e:	be 61 00 00 00       	mov    $0x61,%esi
    1253:	48 89 c7             	mov    %rax,%rdi
    1256:	e8 0e ff ff ff       	callq  1169 <url_encode_char> */
	url_encode_char(j, 'a'); 

    /*125b:	48 8d 45 f3          	lea    -0xd(%rbp),%rax
    125f:	48 89 c6             	mov    %rax,%rsi
    1262:	48 8d 3d 9f 0d 00 00 	lea    0xd9f(%rip),%rdi        # 2008 <_IO_stdin_used+0x8>
    1269:	b8 00 00 00 00       	mov    $0x0,%eax
    126e:	e8 fd fd ff ff       	callq  1070 <printf@plt>*/
	printf("%s\n", j);

    /*1273:	b8 00 00 00 00       	mov    $0x0,%eax
    1278:	48 8b 55 f8          	mov    -0x8(%rbp),%rdx
    127c:	64 48 33 14 25 28 00 	xor    %fs:0x28,%rdx
    1283:	00 00 
    1285:	74 05                	je     128c <main+0x68>
    1287:	e8 d4 fd ff ff       	callq  1060 <__stack_chk_fail@plt>
    128c:	c9                   	leaveq 
    128d:	c3                   	retq   
    128e:	66 90                	xchg   %ax,%ax*/
	return 0;
}
